<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<style>

    .umpires{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        height: 40px;
        margin-bottom: 10px;
    }
    .umpires span{
        margin-right: 20px;
        cursor:pointer;
        font-size: 14px;
    }
    .unactive{
        border-bottom: 2px solid #0d78fc;
        font-size: 16px;
    }

    #tips{
        color: #FF0721;
    }

</style>
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">

                        <!--<div th:text="${examinationResultsComDO}"></div>-->
                        <div id="box"></div>

                        <!--                        <input type="hidden" name="id" >-->
                        <!--                        <input type="hidden" name="type" >-->

                        <!--                        -->

                        <div class="form-group">
                            <label class="col-sm-3 control-label" style="padding-top: 0;">第二次加密序号:</label>
                            <div class="col-sm-8">
                                <span id="serial"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">裁判一:</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text" placeholder="请录入裁判一分数" id="numberReferee1">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">裁判二:</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text"  placeholder="请录入裁判二分数" id="numberReferee2">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">裁判三:</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text"  placeholder="请录入裁判三分数" id="numberReferee3">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注:</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text"  placeholder="请录入备注" id="remark">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="button" onclick="update()" class="btn btn-primary">提交</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" src="/js/webJs/jzweb/record/edit.js"></script>

<script>

    function UrlSearch(){
        var name,value;
        var str=location.href; //取得整个地址栏
        var num=str.indexOf("?")
        str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]

        var arr=str.split("&"); //各个参数放到数组里
        for(var i=0;i < arr.length;i++){
            num=arr[i].indexOf("=");
            if(num>0){
                name=arr[i].substring(0,num);
                value=arr[i].substr(num+1);
                this[name]=value;
            }
        }
    }

    let Request = new UrlSearch();
    let slightTips = true;
    $("#serial").html(Request.num2)

    let signGradeDTO = JSON.parse(sessionStorage.getItem('signGradeDTO'))
    $("#numberReferee1").val(signGradeDTO.markOne)
    $("#numberReferee2").val(signGradeDTO.markTwO)
    $("#numberReferee3").val(signGradeDTO.markThree)
    $("#remark").val(signGradeDTO.remark)

    function update() {

        // cbatchId，signId，numberReferee，competition ,mark
        let score = 0;
        switch (Request.competition) {
            case 'B1': score = 30;break;
            case 'B2': score = 20;break;
            case 'B3': score = 20;break;
            case 'B4': score = 30;break;
        }

        let numberReferee1 = $("#numberReferee1").val(),
            numberReferee2 = $("#numberReferee2").val(),
            numberReferee3 = $("#numberReferee3").val(),
            remark = $("#remark").val();

        if( numberReferee1 < 0 || numberReferee2 < 0 || numberReferee3 < 0 ){
            layer.msg('分数不能小于0');
            return false;
        }

        if ( isNaN(numberReferee1) || isNaN(numberReferee2) || isNaN(numberReferee3) ) {
            layer.msg("输入的值不是数字");
            return false;
        }

        if( numberReferee1 > score || numberReferee2 > score || numberReferee3 > score ){
            layer.msg('最高分限制为'+score);
            return false;
        }

        if( !numberReferee1 || !numberReferee2 || !numberReferee3 ){
            layer.msg('分数不能为空');
            return false;
        }

        // if( slightTips ){
        //     slightTips = false;
        //     $("#tips").show();
        //     return false;
        // }

        var jsonData = {
            remark:$("#remark").val(),
            id: Request.id
        };

        $.ajax({
            type : 'post',
            url : '/signgrade/updateRemark',
            contentType: 'application/json',
            data: JSON.stringify(jsonData),
            success : function(r) {
                // layer.closeAll()
            }
        });

        let signGrades = [
            {
                mark:numberReferee1,
                cbatchId: Request.cbatchId,
                signId: Request.id,
                id: signGradeDTO.signGrades[0].id,
                competition: Request.competition,
                numberReferee:'1'
            },
            {
                mark:numberReferee2,
                cbatchId: Request.cbatchId,
                signId: Request.id,
                id: signGradeDTO.signGrades[1].id,
                competition: Request.competition,
                numberReferee:'2'
            },
            {
                mark:numberReferee3,
                cbatchId: Request.cbatchId,
                signId: Request.id,
                id:  signGradeDTO.signGrades[2].id,
                competition: Request.competition,
                numberReferee:'3'
            }
        ];

        layer.open({
            title : '确认分数',
            area : [ '600px', '400px' ],
            content: '<form class="form-horizontal m-t" id="signupForm">\n' +
                '                        <div id="box"></div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label" style="padding-top: 0;">第二次加密序号:</label>\n' +
                '                            <div class="col-sm-8">\n' +
                '                                <span id="serial">'+ Request.num2 +'</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">裁判一:</label>\n' +
                '                            <div class="col-sm-8">\n' +
                '                                <input class="form-control" type="text" placeholder="请录入裁判一分数" id="numberReferee1" value="'+numberReferee1+'" disabled>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">裁判二:</label>\n' +
                '                            <div class="col-sm-8">\n' +
                '                                <input class="form-control" type="text"  placeholder="请录入裁判二分数" id="numberReferee2" value="'+numberReferee2+'" disabled>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">裁判三:</label>\n' +
                '                            <div class="col-sm-8">\n' +
                '                                <input class="form-control" type="text"  placeholder="请录入裁判三分数" id="numberReferee3" value="'+numberReferee3+'" disabled>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">备注:</label>\n' +
                '                            <div class="col-sm-8">\n' +
                '                                <input class="form-control" type="text"  placeholder="请录入备注" id="remark" value="'+remark+'" disabled>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                    </form>'+
                '<div class="form-group" id="tips"> ' +
                    '       <label class="col-sm-3 control-label"></label>'+
                '       <div class="col-sm-8">请检查分数，确认无误点击提交 完成录入</div></div>',
            yes: function(index, layero){
                $.ajax({
                    cache : true,
                    type : "POST",
                    url : "/signgrade/insertOrUpdate",
                    data : JSON.stringify(signGrades),// 你的formid
                    async : false,
                    contentType: 'application/json',
                    error : function(request) {
                        parent.layer.alert("Connection error");
                    },
                    success : function(data) {
                        if (data.code == 0) {
                            parent.layer.msg("操作成功");
                            parent.reLoad();
                            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                            parent.layer.close(index);

                        } else {
                            parent.layer.alert(data.msg)
                        }

                    }
                });
            },
            success: function(layero, index){

            }
        });

    }

</script>
</body>
</html>
